package com.example.bill.biz;

import com.example.bill.dao.Billmapper;
import com.example.bill.pojo.Bill;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class Billbizimpl implements Billbiz{
    @Autowired
    private Billmapper billmapper;
    @Override
    public PageInfo<Bill> getallbill(int pageno) {
        PageHelper.startPage(pageno, 5);
        List<Bill> list = this.billmapper.getallbill();
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < list.size(); i++) {
            Date date = list.get(i).getCreationDate();
            String s = sd.format(date);
            list.get(i).setCreationDates(s);
        }
        PageInfo<Bill> pageInfo = new PageInfo(list);
    return pageInfo;
    }

    @Override
    public List<Bill> getallbills() {
        return this.billmapper.getallbill();
    }

    @Override
    public Bill getbill(int id) {
        return this.billmapper.getbill(id);
    }



    @Override
    public int insertbill(Bill bill) {
        return this.billmapper.insertbill(bill);
    }

    @Override
    public List<Bill> distinct() {
        return this.billmapper.distinct();
    }

    @Override
    public int delbill(int id) {
        return this.billmapper.delbill(id);
    }

    @Override
    public int updatebill(Bill bill) {
        return this.billmapper.updatebill(bill);
    }

    @Override
    public List<Bill> getbysel(Bill bill) {
        return this.billmapper.getbysel(bill);
    }
}
